﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace lcs.Web.Outstorage
{
    public partial class PrintOutStorage : System.Web.UI.Page
    {
        private decimal totalAllPrice = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["batchid"]) && Session["login"] != null)
                {
                    DataSet ds_user = Session["login"] as DataSet;
                    string user_id = ds_user.Tables[0].Rows[0]["user_id"].ToString();
                    string user_name = ds_user.Tables[0].Rows[0]["user_name"].ToString();

                    Bind(Request["batchid"], user_id,user_name);//
                }
                //if (Session["print_out_storageList_id"] != null)
                //{
                //    string out_storagelist_batchid = Session["print_out_storageList_id"].ToString();

                //    Bind(out_storagelist_batchid);

                //}
                //if (Request["type"] == "r_add")
                //{
                //    if (Session["li_oid_add"] != null)
                //    {
                //        List<string> li_oid_add = Session["li_oid_add"] as List<string>;

                //        BindLi(li_oid_add);
                //    }
                //}

            }
        }

        private void Bind(string out_storagelist_batchid,string user_id,string username)
        {
            lcs.BLL.out_storageList olm = new BLL.out_storageList();

            //注：出库时间是out_storagelist中的预出库时间（out_storage_Estimate）即物料员申请出库的时间，不是仓管员出库操作时所写的时间
            DataSet ds = olm.GetVoutStrorageSpaceList(" out_storagelist_batchid='" + out_storagelist_batchid + "' and cguid=" + user_id);

            if (ds.Tables[0].Rows.Count > 0)
            {
                this.lbl_batchId.Text = out_storagelist_batchid;
                this.lbl_proid.Text = ds.Tables[0].Rows[0]["proid"].ToString();
                this.lbl_project_name.Text = ds.Tables[0].Rows[0]["projectname"].ToString();
                this.lbl_receive_address.Text = ds.Tables[0].Rows[0]["receive_address"].ToString();
                this.lbl_receive_userName.Text = ds.Tables[0].Rows[0]["receive_userName"].ToString();
                this.lbl_receive_userPhone.Text = ds.Tables[0].Rows[0]["receive_userPhone"].ToString();
                this.lbl_username.Text = username;
                this.lbl_date.Text = System.DateTime.Now.ToShortDateString();

                this.GridView1.DataSource = ds;
                this.GridView1.DataBind();
            }

            DataSet ds_checkuser = olm.GetVoutSubmitCheckUser(" out_storagelist_batchid='" 
                + out_storagelist_batchid + "' order by flow_node_num asc");

            if (ds.Tables[0].Rows.Count > 0)
            {
                string checkUsers = "";

                foreach (DataRow r in ds_checkuser.Tables[0].Rows)
                {
                    checkUsers += r["user_name"] +",";
                }
                checkUsers = checkUsers.Substring(0, checkUsers.LastIndexOf(','));
                this.lbl_checkuser.Text = checkUsers;
            }

            #region 以前的方法，从out_stroage中读出库时间
            //lcs.BLL.materialinfo mm = new BLL.materialinfo ();
            //lcs.BLL.out_storageList olm = new BLL.out_storageList();
            //lcs.BLL.out_storage om = new BLL.out_storage();


            //lcs.Model.out_storageList olist = olm.GetModel(out_storageList_id);//出库申请清单

            //lcs.Model.materialinfo m = mm.GetModel(olist.material_id.Value);

            //this.lbl_proid.Text = m.proid;
            //this.lbl_project_name.Text = m.projectname;
            //this.lbl_receive_address.Text = olist.receive_address;
            //this.lbl_receive_userName.Text = olist.receive_userName;
            //this.lbl_receive_userPhone.Text = olist.receive_userPhone;

            //DataSet ds = om.GetOutList(" out_storageList_id=" + out_storageList_id);

            //this.GridView1.DataSource = ds;
            //this.GridView1.DataBind();
            #endregion

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    Label lbl_unprice = e.Row.FindControl("lbl_unprice") as Label;//单价
            //    Label lbl_totalPrice = e.Row.FindControl("lbl_totalPrice") as Label;//金额
            //    Label lbl_nums = e.Row.FindControl("lbl_nums") as Label;//数量
              
            //    decimal unprice = decimal.Parse(lbl_unprice.Text);

            //    lbl_unprice.Text = unprice.ToString("0.00");

            //    decimal nums = decimal.Parse(lbl_nums.Text);

            //    lbl_totalPrice.Text = (unprice * nums).ToString("0.00");

            //    totalAllPrice += unprice * nums;
            //}
            //if (e.Row.RowType == DataControlRowType.Footer)
            //{
            //    Label lbl_totalAllPrice = e.Row.FindControl("lbl_totalAllPrice") as Label;//总计金额

            //    lbl_totalAllPrice.Text = "总计："+totalAllPrice.ToString("0.00");
            //}
        }

       
    }
}